home *** CD-ROM | disk | FTP | other *** search
/ PC Elektro 3 / PC-Elektro-3-cd1.bin / KBan 2.0 / KBANSRC.LZH / SRC / PROG / KBANFUNC.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1997-06-27  |  4.9 KB  |  149 lines

  1. /*
  2.  * the class STAGE and KBAN_FUNCTION
  3.  * Copyright (C) 1996, 1997 Kazutaka Hirata <khirata@jove.acs.unt.edu>
  4.  */
  5.  
  6. #include "stdafx.h"
  7.  
  8. #include "kbanfunc.h"
  9.  
  10. STAGE* STAGE::init(KBAN_INFO& info, KBAN_DRAW& draw)
  11. { return this; }
  12.  
  13. STAGE* STAGE::pre_redraw(KBAN_INFO& info, KBAN_DRAW& draw)
  14. { return this; }
  15.  
  16. STAGE* STAGE::redraw(KBAN_INFO& info, KBAN_DRAW& draw)
  17. { return this; }
  18.  
  19. STAGE* STAGE::shift_up(KBAN_INFO& info, KBAN_DRAW& draw)
  20. { return this; }
  21.  
  22. STAGE* STAGE::shift_down(KBAN_INFO& info, KBAN_DRAW& draw)
  23. { return this; }
  24.  
  25. STAGE* STAGE::control_up(KBAN_INFO& info, KBAN_DRAW& draw)
  26. { return this; }
  27.  
  28. STAGE* STAGE::control_down(KBAN_INFO& info, KBAN_DRAW& draw)
  29. { return this; }
  30.  
  31. STAGE* STAGE::key_in(KBAN_INFO& info, KBAN_DRAW& draw, UINT key, UINT nFlags)
  32. { return this; }
  33.  
  34. STAGE* STAGE::mouse_out (KBAN_INFO& info, KBAN_DRAW& draw)
  35. { return this; }
  36.  
  37. STAGE* STAGE::mouse_move(KBAN_INFO& info, KBAN_DRAW& draw, const XY& pc, UINT nFlags)
  38. { return this; }
  39.  
  40. STAGE* STAGE::mouse_left_up(KBAN_INFO& info, KBAN_DRAW& draw, const XY& pc, UINT nFlags)
  41. { return this; }
  42.  
  43. STAGE* STAGE::mouse_left_down(KBAN_INFO& info, KBAN_DRAW& draw, const XY& pc, UINT nFlags)
  44. { return this; }
  45.  
  46. STAGE* STAGE::mouse_right_up(KBAN_INFO& info, KBAN_DRAW& draw, const XY& pc, UINT nFlags)
  47. { return this; }
  48.  
  49. STAGE* STAGE::mouse_right_down(KBAN_INFO& info, KBAN_DRAW& draw, const XY& pc, UINT nFlags)
  50. { return this; }
  51.  
  52. STAGE* STAGE::user_message(KBAN_INFO& info, KBAN_DRAW& draw, uint wval, long lval)
  53. { return this; }
  54.  
  55. void STAGE::end(KBAN_INFO& info, KBAN_DRAW& draw)
  56. { }
  57.  
  58. int KBAN_FUNCTION::decide_next_stage(KBAN_INFO& info, KBAN_DRAW& draw, STAGE* result)
  59. {
  60.   while(result != m_current_stage) {
  61.     m_current_stage->end(info, draw);
  62.     delete m_current_stage;
  63.     m_current_stage = result;
  64.     if(m_current_stage != NULL) {
  65.       result = m_current_stage->init(info, draw);
  66.     }
  67.     if(result == NULL) {
  68.       m_current_stage = NULL;
  69.       break;
  70.     }
  71.   }
  72.   return (m_current_stage != NULL) ? TRUE : FALSE;
  73. }
  74.  
  75. int KBAN_FUNCTION::init(KBAN_INFO& info, KBAN_DRAW& draw)
  76. {
  77.   m_current_stage = init_new(info, draw);
  78.   STAGE* result = m_current_stage->init(info, draw);
  79.   if(result != m_current_stage) {
  80.     decide_next_stage(info, draw, result);
  81.   }
  82.   return (m_current_stage != NULL) ? MENU_CONTINUE : MENU_END;
  83. }
  84.  
  85. const char* KBAN_FUNCTION::get_name(void)
  86. { return NULL; }
  87.  
  88. STAGE* KBAN_FUNCTION::init_new(KBAN_INFO& info, KBAN_DRAW& draw)
  89. { return NULL; }
  90.  
  91. void KBAN_FUNCTION::end(KBAN_INFO& info, KBAN_DRAW& draw)
  92. {
  93.   if(m_current_stage != NULL) {
  94.     m_current_stage->end(info, draw);
  95.     delete m_current_stage;
  96.     m_current_stage = NULL;
  97.   }
  98. }
  99.  
  100. #define EVENT_FUNCTION(x)                    \
  101.   int ret = TRUE;                        \
  102.   if(m_current_stage != NULL) {                    \
  103.     STAGE* result = x;                        \
  104.     ret = decide_next_stage(info, draw, result);        \
  105.   }                                \
  106.   return ret;
  107.  
  108. int KBAN_FUNCTION::pre_redraw(KBAN_INFO& info, KBAN_DRAW& draw)
  109. { EVENT_FUNCTION(m_current_stage->pre_redraw(info, draw)); }
  110.  
  111. int KBAN_FUNCTION::redraw(KBAN_INFO& info, KBAN_DRAW& draw)
  112. { EVENT_FUNCTION(m_current_stage->redraw(info, draw)); }
  113.  
  114. int KBAN_FUNCTION::shift_up(KBAN_INFO& info, KBAN_DRAW& draw)
  115. { EVENT_FUNCTION(m_current_stage->shift_up(info, draw)); }
  116.  
  117. int KBAN_FUNCTION::shift_down(KBAN_INFO& info, KBAN_DRAW& draw)
  118. { EVENT_FUNCTION(m_current_stage->shift_down(info, draw)); }
  119.  
  120. int KBAN_FUNCTION::control_up(KBAN_INFO& info, KBAN_DRAW& draw)
  121. { EVENT_FUNCTION(m_current_stage->control_up(info, draw)); }
  122.  
  123. int KBAN_FUNCTION::control_down(KBAN_INFO& info, KBAN_DRAW& draw)
  124. { EVENT_FUNCTION(m_current_stage->control_down(info, draw)); }
  125.  
  126. int KBAN_FUNCTION::key_in(KBAN_INFO& info, KBAN_DRAW& draw, UINT key, UINT nFlags)
  127. { EVENT_FUNCTION(m_current_stage->key_in(info, draw, key, nFlags)); }
  128.  
  129. int KBAN_FUNCTION::mouse_out(KBAN_INFO& info, KBAN_DRAW& draw)
  130. { EVENT_FUNCTION(m_current_stage->mouse_out(info, draw)); }
  131.  
  132. int KBAN_FUNCTION::mouse_move(KBAN_INFO& info, KBAN_DRAW& draw, const XY& pc, UINT nFlags)
  133. { EVENT_FUNCTION(m_current_stage->mouse_move(info, draw, pc, nFlags)); }
  134.  
  135. int KBAN_FUNCTION::mouse_left_up(KBAN_INFO& info, KBAN_DRAW& draw, const XY& pc, UINT nFlags)
  136. { EVENT_FUNCTION(m_current_stage->mouse_left_up(info, draw, pc, nFlags)); }
  137.  
  138. int KBAN_FUNCTION::mouse_left_down(KBAN_INFO& info, KBAN_DRAW& draw, const XY& pc, UINT nFlags)
  139. { EVENT_FUNCTION(m_current_stage->mouse_left_down(info, draw, pc, nFlags)); }
  140.  
  141. int KBAN_FUNCTION::mouse_right_up(KBAN_INFO& info, KBAN_DRAW& draw, const XY& pc, UINT nFlags)
  142. { EVENT_FUNCTION(m_current_stage->mouse_right_up(info, draw, pc, nFlags)); }
  143.  
  144. int KBAN_FUNCTION::mouse_right_down(KBAN_INFO& info, KBAN_DRAW& draw, const XY& pc, UINT nFlags)
  145. { EVENT_FUNCTION(m_current_stage->mouse_right_down(info, draw, pc, nFlags)); }
  146.  
  147. int KBAN_FUNCTION::user_message(KBAN_INFO& info, KBAN_DRAW& draw, uint wval, long lval)
  148. { EVENT_FUNCTION(m_current_stage->user_message(info, draw, wval, lval)); }
  149.